var vm = new Vue({
    el:'#rrapp',
	data:{
		roleId : '',
		roleName : '',
		code : '',
		remark : ''
	},
	methods: {
		 GetRequest() {
		   var url = location.search; //获取url中"?"符后的字串   
		   var theRequest = new Object();   
		   if (url.indexOf("?") != -1) {   
		      var str = url.substr(1);   
		      strs = str.split("&");   
		      for(var i = 0; i < strs.length; i ++) {   
		         theRequest[strs[i].split("=")[0]]=unescape(decodeURI(strs[i].split("=")[1]));   
		      }   
		   }   
		   return theRequest;   
		},
		getRoleList(roleId,roleName,code,remark){
			if(code == 1){
				$.ajax({
					url : 'sys/getRoleInfo',
					type: 'post',
					dataType: 'json',
					data: {
						roleId : roleId,
						roleName : roleName
					},
					success: function(result){
						if(result.code == 0){
							var html = '';
							for(var i = 0; i < result.page.length; i++){
								html += '<option value="' + result.page[i].roleId +'">' + (result.page[i].remark==null?result.page[i].roleName:result.page[i].remark) + '</option>';
							}
							$("#roleId").html(html);
						}else{
							alert(result.msg);
						}
					},
					error: function(result){
						alert('获取角色数据失败!');
					}
				});
			}else{
				var html = '<option value="' + roleId + '">' + (remark==undefined?roleName:remark) + '</option>';
				$("#roleId").html(html);
			}
		},
		apply: function() {
			if($("#roleId").val() == ''){
				alert('请选择激活角色');
				return;
			}
			$.ajax({
				url : 'sys/applyActivation',
				type: 'post',
				dataType: 'json',
				data: {
					roleId : $("#roleId").val(),
				},
				success: function(result){
					if(result.code == 0){
						alert('申请成功,等待审核后登录系统');
						location.href='logout';
					}else{
						alert(result.msg);
					}
				},
				error: function(result){
					alert('申请失败!');
				}
			})
		}
	},
	created: function(){
		var obj = this.GetRequest();
		this.roleId = obj.roleId;
		this.roleName = obj.roleName;
		this.code = obj.code;
		this.remark = obj.remark;
		this.getRoleList(this.roleId, this.roleName, this.code, this.remark);
	},
});

